use crate::pool;
use rbatis::{crud, impl_select_page, Page, rbdc::{self, db::ExecResult}, sql::{self, PageRequest}};
use serde::{Deserialize, Serialize};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct TbAttend {
    pub id: Option<u64>,
    pub appid: Option<String>,
    pub username: Option<String>,
    pub ip: Option<String>,
    pub net_point_id: Option<u64>,
    pub time: Option<u64>,
    pub finger_loc: Option<u32>,
    #[serde(rename = "type")]
    pub attend_type: Option<u32>,
}

crud!(TbAttend {});
impl_select_page!(TbAttend{select_page() => ""});

impl TbAttend {
    pub async fn get_attends(
        page: &crate::common::QueryPage,
    ) -> Result<Page<TbAttend>, rbdc::Error> {
        TbAttend::select_page(pool!(), &PageRequest::from(page)).await
    }

    pub async fn insert_attend(attend: &TbAttend) -> Result<ExecResult, rbdc::Error> {
        TbAttend::insert(pool!(), attend).await
    }
}
